package com.cnr.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.cnr.model.Credentials;
import com.cnr.util.ManageCredentials;

@Controller
@RequestMapping("/identify")
public class CredentialController {
	@RequestMapping(method = RequestMethod.POST)
	public String identifyViaPost(@RequestParam("username") String username,
			@RequestParam("password") String password, HttpSession session, Model model) {

		ManageCredentials mu = new ManageCredentials();
		Credentials user = mu.getUser(username, password);

		if (user == null) {
			model.addAttribute("message", "Wrong username/password dude!");
			return "error";
		}
		session.setAttribute("user", user);
		return "identified";
	}
}